
<style type="text/css" media="screen">
     body {
          margin: 0;
     }
     #menu-centered {
          background: #CCC;
          padding: 10px;
          margin-bottom: 10px;
      }
      #menu-centered ul {
           margin: 0;
           padding: 0;
           text-align: left;
      }
      #menu-centered li {
           display: inline;
           list-style: none;
           padding: 10px 5px 10px 5px;
		   border:dashed 2px;
      }
      #menu-centered a {
           font: normal 12px/24px Arial;
           color: #fff;
           text-decoration: none;
           padding: 5px;
           background: #57a8d6;
      }
      #menu-centered a:hover {
           background: #5fb8eb;
      }
 </style>
 
 

<?php
require_once('inc.db.php');


$address =  $_GET['address'];

//echo $address;


$data1 = explode(',',$address);

$pcode=$data1[1];

$data2 = explode(' ',$data1[0]);
$x=count($data2);
$state=$data2[$x-1];
$locality=str_replace($state,'',$data1[0]);


//$pcode=$data2[1];

$result = mysql_query("SELECT * FROM au_suburb_geo WHERE Pcode='$pcode' AND Locality='$locality' AND State1='$state'");


while ($row = mysql_fetch_assoc($result)) {
   		$latitude = $row['Lat'];
		//echo '<br>';
		$longitude = $row['Long'];
}



$sql_distance="SELECT *, ( 6371 * acos( cos( radians($latitude) ) * cos( radians(`lat`) ) * cos( radians(`long`) - radians($longitude) ) + sin( radians($latitude) ) * sin( radians(`lat`) ) ) ) AS distance FROM franchise ORDER BY distance asc";

//echo $sql_distance;

echo '<br>';

$result2=mysql_query($sql_distance);



//echo '<table border="2">';


echo '<table border="1px">';

while($row2 = mysql_fetch_assoc($result2)){
	
	//print_r();
	echo '<tr><td>';
	echo $row2['name'];
	echo '<br>';
	echo $row2['location_addr_street1'];
	echo '<br>';
	echo $row2['location_addr_suburb'];
	echo ' - '; 
	echo $row2['location_addr_state'];
	echo ' - '; 
	echo $row2['location_addr_pcode	'];
	echo '<br>';
	echo $row2['phone'];
	echo '</tr></td>';
	
}
echo '</table>';

//echo $sql_distance;


